#pragma once

#include <iostream>
#include <fstream>
#include <Mmsystem.h>

using namespace std;

class CAutoJoin
{
private:
	ISetting* setting;
	ILang* lang;

public:
	CAutoJoin(CDialog* dlg, ISetting* setting, ILang *lang, CBalloon* balloon);
public:
	~CAutoJoin(void);	

private:
	CProcess* pGarena;
	CWnd* hWndRoom;
	POINT poJoin, poBegin, poEnd;
	CDialog* dlgLine;
	CBalloon* balloon;
	BOOL bJoinNext, bPending, bSafe;
	bool bGG;

	static HWND hWndStartGame;

	CString sfPatchGG, sfRestoreGG, sfPatchGM, sfRestoreGM;

	
	CDialog* dlg;

private:
	
	BOOL IsOnARoom(POINT* po);
	void OnF7();

	void SendJoin(POINT po);
	bool StartJoining();
	void StopJoining();
	static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam);
	static BOOL CALLBACK EnumStartGameButton(HWND hwnd, LPARAM lparam);
	bool PatchGarenaMemory();
	BOOL RestoreGarenaMemory();	
	bool InsertSendMessage(ofstream& fp, ofstream& fr, DWORD dwStart);	
	bool DetectGGMemory();
	bool DetectGMMemory();		
	bool IsJoining();
	bool IsGGPatched();

	void OnTimer(WPARAM wParam);
	int GetRoomLineNo(POINT po);
	void JoinNextRoom();

public:
	LRESULT OnHotKey(WPARAM wp);
	void OnGlobalMouseAction(LPARAM lParam);
};
